﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeJC.DAL.Model;

namespace DeJC.BLL.Managers {
    public static class CityManage
    {
        public static IEnumerable<City> GetCitys()
        {
            IEnumerable<City> cities;
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                cities=unitOfWork.CityRepository.GetAll();
            }
            return cities;
        }

        public static bool AddCity(City city)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                unitOfWork.CityRepository.Add(city);
                unitOfWork.Save();
            }
            return true;
        }

        public static bool UpdateCity(City city, int id)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                var cityEntity = unitOfWork.CityRepository.GetById(id);
                cityEntity.CountryID = city.CountryID;
                cityEntity.Description=city.Description;
                cityEntity.ImagePath=city.ImagePath;
                unitOfWork.Save();
            }
            return true;
        }

        public static bool DeleteCity(int id)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                City city = unitOfWork.CityRepository.GetById(id);
                unitOfWork.CityRepository.Delete(city);
                unitOfWork.Save();
            }
            return true;
        }

        //public List<City> GetCityPaged(int page, int rows, out int totalCount)
        //{
        //    List<City> cities;
        //    using (UnitOfWork unitOfWork = new UnitOfWork())
        //    {
        //        cities= unitOfWork.CityRepository.GetCityPaged(page, rows, out totalCount);
        //    }
        //    return cities;
        //}
        public static City GetById(int id)
        {
            City city;
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                city = unitOfWork.CityRepository.GetById(id);
            }
            return city;
        }
    }
}
